<%@ page language="java" import="java.util.* ,com.pojo.Emp" pageEncoding="utf-8"%>

<%@ taglib  prefix="c"   uri="http://java.sun.com/jsp/jstl/core"  %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'showEmp.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	
	<script type="text/javascript">
		
		function init() {
			//Radio   -> Sex 
			//获取隐藏域中Sex的值
			var hidden_dex = document.frm.hidden_sex.value;
			//获取性别控件  -- > Radio
			var sex = document.frm.sex;
			
			for( var i = 0 ; i<sex.length ; i++) {
				if(hidden_dex == sex[i].value ) {
					sex[i].checked = true;
					break;
				}
			}
			
			
			//Select --> Degree
			//获取隐藏域中Degree的值
			var hidden_degree = document.frm.hidden_degree.value;
			//获取学历控件  -- > Select
			var degree = document.frm.degree;
			
			for(var i = 0 ; i <degree.options.length ; i++) {
				if(hidden_degree == degree.options[i].value) {
					degree.selectedIndex = i ;
					break;
				}
			}
			
			//CheckBox --> Work
			var hidden_work = document.frm.hidden_work.value;   // -->  "oracle , java"    ---> [ oracle , java ] 
			var work = document.frm.work;
			
			var work_array = hidden_work.split(",");
			
			for(var i = 0 ; i<work.length ;i++) {
				for(var j = 0 ; j<work_array.length ; j++) {
					if(work_array[j] == work[i].value ) {
						work[i].checked="checked";
					}
				}
			}
		}
		
	</script>

  </head>
  
  <!--初始化控件函数 -->
  <body  onload="init()">
  
  
<jsp:include page="/jsp/head.jsp"></jsp:include>
  
  
  	<c:set  var="emp"  value="${requestScope.emp }"  />
  
  
    <h4>Update Emp Info</h4>
  
    <form action="servlet/EmpServlet"  method="post"   name="frm">
    	<!-- 调用Servlet中的 updateEmp 方法 -->
    	<input type="hidden"   name="method"  value="updateEmp"   />
    	
    	<!-- 此隐藏域用于保存用户的ID -->
    	<input type="hidden"   name="id"  value="${emp.id }"   />
    
    	<!-- 用隐藏于接收Emp其他控件的信息 -->
    	<!-- 接收 Radio -->
    	<input type="hidden"   name="hidden_sex"  value="${emp.sex }"   /> 
    	<!-- 接收 Select -->
    	<input type="hidden"   name="hidden_degree"  value="${emp.degree }"   />
    	<!-- 接收 CheckBox -->
    	<input type="hidden"   name="hidden_work"  value="${emp.work }"   />
    	
    
    	Name : <input  type="text"  name="name"   value="${emp.name }" /><br/>
    	
    	Sex : <label><input  type="radio""  name="sex"   value="0" />男</label>
    			<label><input  type="radio""  name="sex"  value="1" />女</label>
    			<br/>
    	
    	Degree : 
    		<select name="degree" >
    			<option value="专科" >专科</option>
    			<option value="本科" >本科</option>
    			<option value="硕士" >硕士</option>
    			<option value="博士" >博士</option>
    	
    		</select> <br/>
    		
    	Work : 
    		<label><input  type="checkbox""  name="work"   value="oracle" />oracle</label>
    		<label><input  type="checkbox""  name="work"    value="java"  /> java</label>
    		<label><input  type="checkbox""  name="work"    value="android"  />android </label>
    		<label><input  type="checkbox""  name="work"     value="ajax" /> ajax</label>
    		<br/>
    		
    	 
    	
    		
    		<input type="submit" value="Reg"/>
    </form>
  </body>
</html>
